﻿using ChiDao.Business.Models.Account;
using ChiDao.Business.Models.Security;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace ChiDao.Business.Service.CommonSupport
{
    /// <summary>
    ///     当前用户信息（含菜单、权限）--此处做了缓存处理
    /// </summary>
    public class CurrentUser
    {
        public CurrentUser()
        {
            //if (!HttpContext.Current.User.Identity.IsAuthenticated)
            //    throw new Exception("用户未登录");  //必须要用户Form验证后才能使用CurrentUser

            //var cache = ContainerFactory.GetContainer().Resolve<ICache>();
            //if (cache.GetSessionCache("currentuser") == null)
            //{
            //    var authorityFacade = ContainerFactory.GetContainer().Resolve<IAuthorityFacade>();
            //    UserInfo = authorityFacade.GetHospUserByName(HttpContext.Current.User.Identity.Name);
            //    MenuPermission = authorityFacade.GetMenusByUserId(UserInfo.Id);
            //    ActionPermission = authorityFacade.GetActionsByUserId(UserInfo.Id);
            //    cache.SetSessionCache("currentuser", this);
            //}
            //else
            //{
            //    var u = (CurrentUser)cache.GetSessionCache("currentuser");
            //    UserInfo = u.UserInfo;
            //    MenuPermission = u.MenuPermission;
            //    ActionPermission = u.ActionPermission;
            //}
        }
        //用户信息
        public Person UserInfo { get; set; }

        //菜单权限
        public IList<MenuInfo> MenuPermission { get; set; }

        //功能权限
        public IList<ActionInfo> ActionPermission { get; set; }

    }
}